/*
 * A CORBA Generic Server
 * Part of the GICOM project
 */
package gicom.config;

import com.sun.corba.se.impl.orbutil.ORBConstants;
import java.util.Properties;

/**
 * provides the configuration of a ORB
 * @author Guillaume Missonnier
 */
public class ORBConfig extends GenericConfig {
    
    /**
     * The ORB's port
     */
    private String port;
    
    /**
     * The ORB's initialHost
     */
    private String initialHost;
    
    /**
     * The ORB initialPort
     */
    private String initialPort;
    
    private String serverHost;
    
    public ORBConfig (String id) throws Exception {
        super("orb_", id);
        this.load();
    }
    
    protected void doSave () throws Exception {
        // Build the properties
        Properties properties = new Properties();
        properties.setProperty("port",getPort());
        properties.setProperty("initialHost",getInitialHost());
        properties.setProperty("initialPort",getInitialPort());
	properties.setProperty("serverHost", getServerHost());
        // Save the properties
        saveProperties(properties);
    }
    
    protected void doLoad () throws Exception {
        Properties properties = loadProperties();
        port = properties.getProperty("port");
        if (port == null) throw new Exception("Port is not define.");
        initialHost = properties.getProperty("initialHost");
        if (initialHost == null) throw new Exception("InitialHost is not define.");
        initialPort = properties.getProperty("initialPort");
        if (initialPort == null) throw new Exception("InitialPort is not define.");
	serverHost = properties.getProperty("serverHost");
	if (serverHost== null)
	    throw new Exception("ServerHost is not define.");
    }
    
    /**
     * Build the properties object to instanciate the ORB
     * @return The ORB's Properties
     */
    public Properties getProperties () {
        Properties properties = new Properties ();
        properties.setProperty(ORBConstants.SERVER_ID_PROPERTY,getId());
        properties.setProperty(ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY,getPort());
        properties.setProperty(ORBConstants.INITIAL_HOST_PROPERTY,getInitialHost());
        properties.setProperty(ORBConstants.INITIAL_PORT_PROPERTY,getInitialPort());
	properties.setProperty(ORBConstants.SERVER_HOST_PROPERTY, getServerHost());
        return properties;
    }

    public String getPort() {
        return port;
    }

    public String getInitialHost() {
        return initialHost;
    }

    public String getInitialPort() {
        return initialPort;
    }
    
    public String getServerHost(){
	return this.serverHost;
    }
    
}
